package top.roadvast.inet.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Author 郭泽鹏
 * @Date 2022/1/11 10:10
 * @Version 1.0
 * @Description
 */
@RestController
public class InetController {

    @Value("${app.version}")
    private String version;


    @GetMapping("/")
    public String helloWorld() {
        return "Welcome to use Inet. | version = " + version + "\n";
    }

    @GetMapping("/host")
    public String getHost() {
        InetAddress localhost = null;
        try {
            localhost = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        if (localhost != null) {
            return "host_name = " + localhost.getHostName() + "<br/>" + "ip_address = " + localhost.getHostAddress() + "\n";
        } else {
            return "";
        }
    }
}
